require("./variable.less");
require("./bootstrap.css");
require("./nav.js");
var _user = require("service/user-service.js");
var _cart = require("service/cart-service.js");

var page = {
  init : function () {
    this.bindEvent();
    this.loadCartProductCount();
  },
  loadCartProductCount : function(){
    _cart.getCartProductCount(function(res){
      $(".cart-count").html(res);
    },function(err){
      console.log(err);
    })
  },
  bindEvent : function(){
  	$(document).on("click",".logout",function(){
  		_user.logout(function(res){
  			window.location.href = "./login.html"
  		},function(err){
  			err(err);
  		});
		})
    $(document).on('click','.toTop',function(){
      $("html,body").animate({scrollTop:0}, 500);
		})
    $(document).on('scroll',function(){
			if($(window).scrollTop() > 0){
				$('.toTop').fadeIn();
			} else {
				$('.toTop').fadeOut();
			}
		})	

    //搜索
    $(document).on("click",".search",function(){
      window.location.href = "./category.html?keyword="+ $(this).siblings("input").val();
    })	
  }
}


$(function(){
  page.init();
})